package com.scienview.test;

import java.lang.reflect.Method;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.scienview.core.anotation.Access;
import com.scienview.core.enums.Level;

public class Permission {

	private String clazzName;
	private String taskName;
	private String taskCode;
	private String mapping;
	private Level level;
	public String getClazzName() {
		return clazzName;
	}
	public void setClazzName(String clazzName) {
		this.clazzName = clazzName;
	}
	public String getTaskName() {
		return taskName;
	}
	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}
	public String getTaskCode() {
		return taskCode;
	}
	public void setTaskCode(String taskCode) {
		this.taskCode = taskCode;
	}
	public String getMapping() {
		return mapping;
	}
	public void setMapping(String mapping) {
		this.mapping = mapping;
	}
	public Level getLevel() {
		return level;
	}
	public void setLevel(Level level) {
		this.level = level;
	}
	
	@Override
	public String toString(){
		return new StringBuffer().append("className:").append(this.clazzName).append(",taskName:").append(this.taskName)
		.append(",taskCode:").append(this.taskCode).append(",mapping:").append(this.mapping).append("\r\n").toString();
	}
	
	public Permission padding(Method method){
		String  suffix=method.getReturnType().equals(ModelAndView.class)?".html":".json";
		this.mapping=method.getAnnotation(RequestMapping.class).value()[0]+suffix;
		Access access=method.getAnnotation(Access.class);
		this.taskCode=access.task();
		this.level=access.level();
		this.taskName=access.task();
		this.clazzName=method.getDeclaringClass().getName();
	
		return this;
	}
}
